import { getcarList } from '../api'
import { getcar } from '../api';

import { addcar } from '../api';
import { delcar } from '../api';

import { getpathList } from '../api';
import { getpath } from '../api';
import { addpath } from '../api';
import { delpath } from '../api';
//import axios from 'axios'
const state = {
   
    carlist: [],
    car: {},
    isshow: false,
    pathlist:[],
    path:{}
};
const mutations = {
    isshow(state) {
        state.isshow = !state.isshow
    },
   
    CARLIST(state, carlist) {

        state.carlist = carlist
    },
    CAR(state, car) {

        state.car = car

    },
    PATHLIST(state, pathlist) {

        state.pathlist = pathlist
    },
    PATH(state, path) {

        state.path = path

    }

};
const actions = {
   
    //查找所有车辆
    async carList({ commit }) {
        let result = await getcarList();
        
        if (result.status == 200) {
            commit("CARLIST", result.data);
        }
    },
    //通过车牌查找车辆
    async carbyid({ commit }, tel = []) {
        let result = await getcar(tel);
        if (result.status == 200) {

            commit("CAR", result.data);
        }
    },
    //添加车辆
    async addCar({ commit }, tel = []) {
        await addcar(tel);
    },
    //删除车辆
    async delCar({ commit }, id = []) {
        await delcar(id);
    },


    //查找所有路线
    async pathList({ commit }) {
        let result = await getpathList();
        console.log(result, 'hh')
        if (result.status == 200) {
            commit("PATHLIST", result.data);
        }
    },
    //通过站点查找路线
    async pathbypass({ commit }, pass = []) {
        let result = await getpath(pass);
        if (result.status == 200) {

            commit("PATH", result.data);
        }
    },
    //添加路线
    async addPath({ commit }, tel = []) {
        await addpath(tel);
       
    },
    //删除路线
    async delPath({ commit }, id = []) {
        await delpath(id);
    }
};
const getters = {};


export default {

    state,
    mutations,
    actions,
    getters
}